package com.lepu.app.fun.index.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lepu.app.fun.index.bean.BeanIndexBook;
import com.lepu.pasm.R;

public class IndexBookAdapter extends BaseAdapter {

	private LayoutInflater layoutInflater = null;
	@SuppressWarnings("unused")
	private Context context = null;
	private ArrayList<BeanIndexBook> knowList;
	
	public IndexBookAdapter(Context context , ArrayList<BeanIndexBook> knowList) {
		this.context = context;
		this.knowList = knowList;
		layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		
		return knowList.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		final ViewHolder holder;

		if (convertView == null) {
			convertView = layoutInflater.inflate(R.layout.index_book_item, null);

			holder = new ViewHolder();
			TextView nameTextView = (TextView) convertView.findViewById(R.id.book_name);
			TextView authorTextView = (TextView) convertView.findViewById(R.id.book_author);
			ImageView imageView = (ImageView) convertView.findViewById(R.id.book_image);

			holder.nameTextView = nameTextView;
			holder.authorTextView = authorTextView;
			holder.imageView = imageView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
        
		holder.nameTextView.setText(knowList.get(position).title);
		holder.authorTextView.setText("主编:  "+knowList.get(position).author);
		holder.imageView.setBackgroundResource(knowList.get(position).imageUrl);

		return convertView;
	}
	
	static class ViewHolder {
		TextView nameTextView;
		TextView authorTextView;
		ImageView imageView;
	}
}
